/* counter.h
 * Counter is concurrency save. Operation counter_increase is done in a critical section. 
 * Counter can be created once.
 * It's uses shared memory and semphores in implementation.
 */
#ifndef _COUNTER_H_
#define _COUNTER_H_

struct counter_t {
  int shm_id;
  int mutex_id;
  int * counter;
  int error;
};

/* Create a counter with inital value 0. */
struct counter_t counter_create();

/* Increases value of counter and returns it's current value. Operation is done in critical section. */
int counter_increment(struct counter_t);

/* Dettaches couter form process, required to be done before any process end... */
void counter_deattach(struct counter_t);

/* ...and last process have to destroy counter */
void counter_destroy(struct counter_t);

#endif
